

* Author: Karin Kitchens 


**********************************************************
* Dependent variables of interest:
**********************************************************

* Per Pupil Local Expenditures at the School District and County Level
* Variation in in per pupil local expenditures at the county level 
* Per Pupil State and Federal expenditures (as checks)
* Per pupil total spending (as a test of overall patterns 
* Percent of Students enrolled in public school 

* Additional Possibilities: 
* Choice (charter and private)  
* Quality (would need additional data for this one)

**********************************************************
* Key independent variables:
**********************************************************

* Diversity: 
* Percent Black, Percent Hispanic, Percent Asian
* Change in diversity- 5 year change in percent Black, percent Hispanic (change_black_5years and change_hispanic_5years)

* Racial Segregation: 
* Dissimilarity Index White/Black 
* varnames: dissim_wb_county_ipo
* Theil Index White/Black and all groups


* Income Segregation:
* Dissimilarity Index between poverty and affluent (income_seg_dist_ipo, income_seg_county_ipo, income_seg_cbsa_ipo)

**********************************************************
* Additonal Controls:
**********************************************************

* Number of Students in District (V33)
* Median Household Income in thousand dollars (median_hh_income_thous) 
* Log of the population (log_pop)
* Percent of residents with bachelor degree or hgiher (bach_orgreater_ipo)
* Percent of the presidential vote for democrats at the county level (pres_dem_vote)  
* Own Home is percent of residents that own their home (own_home_ipo)
* aland10 is the size in area of the school district based on 2010 district boundaries (aland10)
* Per pupil state expenditures to the district (per_pupil_state)
* Per pupil federal expenditures to the district  (per_pupil_fed)


* create global to use in regressions
global indep V33 median_hh_income_thous log_pop bach pres_dem own_home_ipo aland10 per_pupil_state_thous per_pupil_fed_thous

* Additional Controls but don't have for all years 
* Number of private schools (num_privschools or num_priv_adjust)
* Number of charter schools (charter_school_count)
* Percent of students receving Special Education (per_IEP)
* Percent of students on free lunch (per_free)
* Percent of students enrolled in public school (percent_public)
      
global indep_add num_priv_adjust charter_school_count per_IEP per_free  
 

**********************************************************
* Additonal Adjustments to data set:
**********************************************************

* Population within school district needs to be greater than 5,000: log_pop>=8.517
* In some models, county and district must be different: same_as_count==0

* State level random intercepts are included: state
* County level random intercepts are included: county

***********************************************************
* Data 
***********************************************************

use main_analysis_data, clear

tsset ncesid year, yearly
sort ncesid year



********************************************
* Models and figures for paper
********************************************


* Figure 1

* Local Spending
bysort state:  egen states_mean =mean(per_pupil_local) if year==2000 & tract_count>1 & ~missing(per_pupil_local_thous)
sort states_mean
egen state_order=group(states_mean) if year==2000 & tract_count>1 & ~missing(per_pupil_local_thous)
order state state_order states_mean
* Need to run this if the computer doesn't have it: install labutil
labmask state_order, values(State)

twoway scatter state_order per_pupil_local  if year==2000 & tract_count>1 & ~missing(per_pupil_local_thous), msize (tiny)  || connected state_order states_mean  if year==2000 & tract_count>1 & ~missing(per_pupil_local_thous), connect(L) clwidth (thick) clcolor (black) scheme(s1mono) mcolor (black) msymbol (none)  || , ytitle("State") xtitle("Per Child Local Revenue") ytitle("State")  legend(order(1 "School District Local Revenue" 2 "State Mean")) title("Per Child Local Revenue by State in 2000") ylabel(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 , valuelabel angle(0) labsize(tiny))
graph export "per_pupil_state.pdf", as(pdf) replace


 
***************************************************************************************************************** 
* keep what I am interested in: some diversity, more than one census tract, and exist for all time periods
* Require the data to have at least one census tract and an African American population in at least one year 
 
 * Define sample 
 sort ncesid year
 xtreg f1.per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  ,  fe i(ncesid) vce(cluster ncesid)
  
 gen sample_part1=e(sample)
 
 * create table 1
 gen var=" "
 
 gen mean_1995=.
 gen n_1995=.
 
 gen mean_2000=.
 gen n_2000=.
 
 gen mean_2010=.
 gen n_2010=.
 
 local n=1

 * Table B.1 in the online appendix 
 * create summary statististics  
 foreach var in per_pupil_local_thous per_pupil_state per_pupil_fed TheileH_wb_ipo TheileH_wh_ipo TheileH_wnw_ipo income_seg_dist_ipo dissim_wb_ipo hindex_wb_schoollev hindex_wh_schoollev hindex_fp_schoollev per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  median_hh_income_thous log_pop bach pres_dem own_home_ipo aland10  V33  num_privschools_ipo charter_school_count per_IEP per_free  { 
 
      replace var="`var'" if _n==`n'
 
	 sum `var' if year==1995 & black_count>0 & tract_count>1 & sample_part1
	 replace mean_1995=r(mean) if _n==`n'
	 replace n_1995=r(N) if _n==`n'
	 
	 sum `var' if year==2000  & black_count>0 & tract_count>1 & sample_part1
	 replace mean_2000=r(mean) if _n==`n'
	 replace n_2000=r(N) if _n==`n'
	  
	 sum `var' if year==2010  & black_count>0 & tract_count>1 & sample_part1
	 replace mean_2010=r(mean) if _n==`n'
	 replace n_2010=r(N) if _n==`n'
	 
 local n=`n'+1
 
 }

 
******************************************************
* Large N-Analysis  
******************************************************




* in order to use robust standard errors- cannot use the f1.per_pupil_local_thous; create new variable instead
sort ncesid year
gen f1per_pupil_local_thous=f1.per_pupil_local_thous


eststo tab2: mixed f1per_pupil_local_thous c.TheileH_wnw_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
eststo tab4: mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
sum TheileH_wb_ipo, detail
margins, at(TheileH_wb_ipo=0.016)
margins, at(TheileH_wb_ipo=0.098)

eststo tab5: mixed f1per_pupil_local_thous c.TheileH_wh_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
eststo tab6: mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.TheileH_wh_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)

***************************
* Figure 2 in main text 
***************************
margins, at(  TheileH_wb_ipo=(0(.1).6))
marginsplot, legend(order(3 "White-Black Segregation, Residential")) recast(line) recastci(rarea) scheme(s1mono) title("Per Child Local Revenue") ytitle("Per Child Local Revenue (In Thousands)") xtitle("White-Black Segregation, Residential") scale(1.2)
graph export "graph_part1a_wb.pdf", as(pdf) replace

margins, at(  TheileH_wh_ipo=(0(.1).6))
marginsplot, legend(order(3 "White-Hispanic Segregation, Residential")) recast(line) recastci(rarea) scheme(s1mono) title("Per Child Local Revenue") ytitle("Per Child Local Revenue (In Thousands)") xtitle("White-Hispanic Segregation, Residential") scale(1.2)
graph export "graph_part1a_wh.pdf", as(pdf) replace



eststo tab7: xtreg f1per_pupil_local_thous c.TheileH_wb_ipo TheileH_wh_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  ,  fe i(ncesid) vce(cluster ncesid)


***************************
* Table 1 in the main text 
***************************
 
esttab  tab2  tab4 tab5 tab6 tab7 using "table2_new.tex" , replace label cells(b(star fmt(2)) se(par fmt(3) ) )  width(0.8\hsize)  title(Regression table\label{tab1}) ///
drop(lns1_1_1:_cons lns2_1_1:_cons lnsig_e:_cons  1995.year 1996.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year 2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009.year 2010.year) 

 
 



*****************************************************
* Robustness checks part 1, runs to create Figure 3
*****************************************************
tsset ncesid year, yearly
sort ncesid year

gen f2per_pupil_local_thous=f2.per_pupil_local_thous
gen f3per_pupil_local_thous=f3.per_pupil_local_thous
gen f10per_pupil_local_thous=f10.per_pupil_local_thous

eststo rob0: mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if  tract_count>1 &  black_count>0   || state: ||ncesid: , vce(robust)

* different time frames in the future 
eststo rob1: mixed f2per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if  tract_count>1 &  black_count>0   || state: ||ncesid:  , vce(robust)
eststo rob2: mixed f10per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if  tract_count>1 &  black_count>0   || state: ||ncesid:  , vce(robust)
eststo rob3: mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if  tract_count>1 &  black_count>0 & (year==1995 | year==1997 | year==2002 | year==2007 | year==2010)  || state: || ncesid: , vce(robust) 

* more variables:  per_free  per_IEP percent_public unemployed_total_ipo   dissim_wb_ipo charter_school_count has_charter citizen_access
eststo rob4: mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  per_free  per_IEP percent_public unemployed_total_ipo  charter_school_count  $indep i.year if  tract_count>1 &  per_black_ipo>0  || state: ||ncesid:  , vce(robust)
eststo rob5: mixed f1per_pupil_local_thous c.dissim_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years   $indep i.year if  tract_count>1 &  black_count>0 ,  || state: ||ncesid:  , vce(robust)
eststo rob13: mixed f1per_pupil_local_thous  isolation_b_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years   $indep i.year if  tract_count>1 &  black_count>0 ,  || state: ||ncesid:  , vce(robust)

* log dependent variable 
gen f1log_per_pupil_local_thous= log(f1per_pupil_local_thous)
eststo rob6: mixed f1log_per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0 ,  || state: ||ncesid:  , vce(robust)


* state only
eststo rob7: mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0 ,  || state:  , vce(robust)


* fixed effects 
gen per_pupil_lead=f1.per_pupil_local_thous
tab region, g(region_)

eststo rob8: mixed per_pupil_lead c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years unemployed_total_ipo  charter_school_count  $indep region_2 region_3 region_4 i.year if  tract_count>1 & black_count>0   || state: ||ncesid:  , vce(robust)

eststo rob9: xtreg per_pupil_lead c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years unemployed_total_ipo  charter_school_count  $indep i.year if  tract_count>1 & black_count>0 ,  fe i(state) 	robust		


tsset ncesid year, yearly
sort ncesid year

eststo rob10: xtreg f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  $indep i.year if tract_count>1 &  black_count>0 ,  fe i(ncesid) robust
eststo rob11: xtreg f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years   $indep i.year if  tract_count>1 &  black_count>0 ,  fe i(ncesid) vce(cluster ncesid)

* segregation by income 

eststo rob12: xtreg f1per_pupil_local_thous income_seg_dist_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0 ,  fe i(ncesid) vce(cluster ncesid)


***********************
* Create Figure 3
***********************
 coefplot (rob0, rename(TheileH_wb_ipo = rob0)) (rob1, rename(TheileH_wb_ipo = rob1)) (rob2, rename(TheileH_wb_ipo = rob2)) (rob3, rename(TheileH_wb_ipo = rob3)) ///
           (rob4, rename(TheileH_wb_ipo = rob4)) (rob5, rename(dissim_wb_ipo  = rob5)) (rob13, rename(isolation_b_ipo= rob13)) (rob6, rename(TheileH_wb_ipo = rob6)) ///
		    (rob7, rename(TheileH_wb_ipo = rob7))  (rob8, rename(TheileH_wb_ipo = rob8))  (rob9, rename(TheileH_wb_ipo = rob9)) ///
			(rob10, rename(TheileH_wb_ipo = rob10)) (rob11, rename(TheileH_wb_ipo = rob11)) (rob12, rename(income_seg_dist_ipo = rob12)), ///
			  grid( glcolor(white)) keep(TheileH_wb_ipo dissim_wb_ipo isolation_b_ipo income_seg_dist_ipo  ) ///
			  xtitle("Per Child Local Revenue (in thousands)") xline(0)   msymbol(D) mfcolor(white) scheme(s1mono) legend(off)  mlabel format( %9.2f) mlabposition(12) mcolor(black) ciopts(lcolor(black))   ///
			     graphregion(margin(l=55)) yscale(alt noline) subtitle("95% CI on White-Black Segregation Coefficient") title("Predicting Local Revenue across Models ") ///
				 order(rob0 rob1  rob2 rob3  rob4 rob5 rob13 rob6 rob7 rob8 rob9  rob10 rob11  rob12  .) ///
	coeflabels(rob0= "1. Original Model" rob1 = "2. Two Years Ahead" rob2 = "3. Ten Years Ahead"  rob3= "4. Years 95, 97, 02, 07, 10" ///
		  rob4 = "5. Add Indep Vars" rob5="6. Dissimilarity Index" rob13="7. Isolation Index" rob6="8. Log Dep Variable" ///
	           rob7 = "9. State RE" rob8 = "10. Region FE" rob9 = "11. State FE" rob10 = "12. District FE"  rob11= "13. Dist FE + Clustered Errors" rob12="14. Income Segregation" /// 
				  , wrap(30) notick labgap(-125)) headings(rob0="Model Specification: "rob1="Varying Time Frames" rob4 ="Change in Variables" rob7 = "Change in Model"  rob12="Segregation by Income",	 labgap(-130) nogap  labsize(medlarge) labcolor(gray)) 
		graph export "graph_robust.pdf", as(pdf) replace
		
		

		
		
*************************************************************
* Robustness Check- Change the dependent variable 
*************************************************************

* create new per pupil measures for other spending (but keep it consistent with what schools are in the other model)

* per capita instead of per pupil
gen per_cap_local=TLOCREV/total_people_ipo


* total expenditures
gen per_pupil_expen=TOTALEXP/V33 if ~missing(per_pupil_local_thous) 

* spent on education (no outlays)
gen per_pupil_currentexp=(TCURELSC - V91 - V92)/V33 if ~missing(per_pupil_local_thous) 
		
* instruction
gen per_pupil_instruction= TCURINST/V33 if ~missing(per_pupil_local_thous) 

* cap outlay
gen per_pupil_capout= TCAPOUT/V33 if ~missing(per_pupil_local_thous) 

* transfers to private/charter school
gen per_pupil_transfer=(V91+V92)/V33 if ~missing(per_pupil_local_thous) 

* per pupil state 
tsset ncesid year, yearly
sort ncesid year
gen f1per_state=f1.per_pupil_state/1000
gen f1per_fed=f1.per_pupil_fed/1000



gen f1per_cap_local= f1.per_cap_local
gen f1per_pupil_expen = f1.per_pupil_expen 
gen f1per_pupil_currentexp = f1.per_pupil_currentexp 
gen f1per_pupil_instruction = f1.per_pupil_instruction
gen f1per_pupil_capout = f1.per_pupil_capout

eststo robd0: mixed f1per_cap_local c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  V33 median_hh_income_thous log_pop bach pres_dem per_pupil_state per_pupil_fed i.year if  tract_count>1 &  black_count>0   || state: ||ncesid: , vce(robust)
eststo robd3: mixed f1per_pupil_expen c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  V33 median_hh_income_thous log_pop bach pres_dem  i.year if  tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
eststo robd4: mixed f1per_pupil_currentexp c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  V33 median_hh_income_thous log_pop bach pres_dem  i.year if  tract_count>1 &  black_count>0   || state: ||ncesid: , vce(robust)
eststo robd5: mixed f1per_pupil_instruction c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  V33 median_hh_income_thous log_pop bach pres_dem  i.year if  tract_count>1 &  black_count>0   || state: ||ncesid:  , vce(robust)
eststo robd6: mixed f1per_pupil_capout c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years  V33 median_hh_income_thous log_pop bach pres_dem  i.year if  tract_count>1 &  black_count>0   || state: ||ncesid: , vce(robust)

		
*************************************************************
* Create Figure B.1 
*************************************************************

	
	
	 coefplot (robd0, rename(TheileH_wb_ipo = rob0))  (robd3, rename(TheileH_wb_ipo = rob3)) ///
           (robd4, rename(TheileH_wb_ipo = rob4)) (robd5, rename(TheileH_wb_ipo  = rob5)) (robd6, rename(TheileH_wb_ipo = rob6)), omitted base ///
		 		  grid( glcolor(white)) keep(TheileH_wb_ipo dissim_wb_ipo income_seg_dist_ipo ) xtitle("Per Child Revenue/Expenditures (in thousands)") xline(0)  msymbol(D) mfcolor(white) scheme(s1mono) legend(off)  ///
			     graphregion(margin(l=45)) yscale(alt noline) subtitle("95% CI on White-Black Segregation Coefficient") title("Predicting Other Types of Rev/Expenditures") ///
	coeflabels(rob0 = "1. Per Capita Local Rev"   rob3= "2. Total Expenditures" ///
		  rob4 = "3. Current Expenditures" rob5="4. Instructional" rob6="5. Capital Outlay" ///
	           		  , wrap(30) notick labgap(-125))  heading( rob0 = "{bf:Per Capita}" rob3  = "{bf:Per Child}" ///
            , labcolor(gray) labgap(-127))
		graph export "graph_robust_dep.pdf", as(pdf) replace


		
*************************************************************
* Create Figure B.2 
************************************************************


eststo frt1 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==1995 || state:  , vce(robust)
eststo frt2 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==1996 || state:  , vce(robust)
eststo frt3 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==1997 || state:  , vce(robust)
eststo frt4 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==1998 || state:  , vce(robust)
eststo frt5 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==1999 || state:  , vce(robust)
eststo frt6 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0  & year==2000 || state:  , vce(robust)
eststo frt7 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0  & year==2001 || state:  , vce(robust)
eststo frt8 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0  & year==2002 || state:  , vce(robust)
eststo frt9 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0  & year==2003 || state:  , vce(robust) 
eststo frt10 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0  & year==2004 || state:  , vce(robust)
eststo frt11 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==2005 || state:  , vce(robust)
eststo frt12 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==2006 || state:  , vce(robust)
eststo frt13 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==2007 || state:  , vce(robust)
eststo frt14 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==2008 || state:  , vce(robust)
eststo frt15 : mixed f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==2009 || state:  , vce(robust)
eststo frt16 : mixed f1per_pupil_local_thous  c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if tract_count>1 &  black_count>0 & year==2010 || state:  , vce(robust)
		
		
		
		 coefplot (frt1, rename(TheileH_wb_ipo = rob0)) (frt2, rename(TheileH_wb_ipo = rob1)) (frt3, rename(TheileH_wb_ipo = rob2)) (frt4, rename(TheileH_wb_ipo = rob3)) ///
           (frt5, rename(TheileH_wb_ipo = rob4)) (frt6, rename(TheileH_wb_ipo  = rob5)) (frt7, rename(TheileH_wb_ipo = rob6)) ///
		    (frt8, rename(TheileH_wb_ipo = rob7))   (frt9, rename(TheileH_wb_ipo = rob8)) ///
			(frt10, rename(TheileH_wb_ipo = rob10)) (frt11, rename(TheileH_wb_ipo = rob11)) (frt12, rename(TheileH_wb_ipo = rob12)) ///
			(frt13, rename(TheileH_wb_ipo = rob13)) (frt14, rename(TheileH_wb_ipo = rob14)) (frt15, rename(TheileH_wb_ipo = rob15)) (frt16, rename(TheileH_wb_ipo = rob16)), ///
			  grid( glcolor(white)) keep(TheileH_wb_ipo  ) xtitle("Per Child Local Revenue (in thousands)")    msymbol(D) mfcolor(white) scheme(s1mono) legend(off)   ///
			     graphregion(margin(l=30)) yscale(alt noline) title("Over Time Comparison: 1995 to 2010") subtitle("95% CI on White-Black Segregation Coefficient") ///
	coeflabels(rob0= "1995" rob1 = "1996" rob2 = "1997"  rob3= "1998" ///
		  rob4 = "1999" rob5="2000" rob6="2001" rob7="2002" rob8="2003" rob10="2004" ///
	           rob11 = "2005" rob12 = "2006" rob13 = "2007"  rob14= "2008" rob15="2009" rob16="2010" /// 
				  , wrap(30) notick labgap(-115))  
		graph export "graph_time.pdf", as(pdf) replace	

		
		


		


***************************
* Create Table B.2
***************************

eststo tab4_school: mixed f1per_pupil_local_thous c.hindex_wb_schoollev_ipo  c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
eststo tab5_school: mixed f1per_pupil_local_thous c.hindex_wh_schoollev_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
eststo tab6_school: mixed f1per_pupil_local_thous c.hindex_wb_schoollev_ipo  c.hindex_wh_schoollev_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
eststo tab7_school: xtreg f1per_pupil_local_thous hindex_wb_schoollev_ipo hindex_wh_schoollev_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0 , fe i(ncesid) vce(cluster ncesid)

esttab   tab4_school tab5_school tab6_school tab7_school using "table2_school.tex" , replace label cells(b(star fmt(2)) se(par fmt(3) ) )  width(0.8\hsize)  title(Regression table\label{tab1}) drop(lns1_1_1:_cons lns2_1_1:_cons lnsig_e:_cons  1995.year 1996.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year 2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009.year 2010.year) 


* Graphs
eststo tab4_school: mixed f1per_pupil_local_thous c.hindex_wb_schoollev_ipo  c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
sum hindex_wb_schoollev, detail
margins, at(  hindex_wb_schoollev_ipo=(0(.1).6))
marginsplot, legend(order(3 "White-Black Segregation, School")) recast(line) recastci(rarea) scheme(s1mono) title("Per Child Local Revenue") ytitle("Per Child Local Revenue (In Thousands)") xtitle("White-Black Segregation, School") scale(1.2)
graph export "graph_part1a_wb_school.pdf", as(pdf) replace


eststo tab4_school: mixed f1per_pupil_local_thous c.hindex_wh_schoollev_ipo  c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if tract_count>1 &  black_count>0  || state: ||ncesid: , vce(robust)
margins, at(  hindex_wh_schoollev_ipo=(0(.1).6))
marginsplot, legend(order(3 "White-Hispanic Segregation, School")) recast(line) recastci(rarea) scheme(s1mono) title("Per Child Local Revenue") ytitle("Per Child Local Revenue (In Thousands)") xtitle("White-Hispanic Segregation, School") scale(1.2)
graph export "graph_part1a_wh_school.pdf", as(pdf) replace
	
		
		
		


***************************
* Create Table B.3
***************************

gen f1percent_public=f1.percent_public
gen studentenrolled_log=log(V33)

gen f1studentenrolled_log=f1.studentenrolled_log
eststo per_public1: mixed f1percent_public TheileH_wb_ipo TheileH_wh_ipo  court_order per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years per_free  own_home_ipo aland10 median_hh_income_thous log_pop bach pres_dem per_pupil_expen  percent_catholic__90_10_ipo i.year if tract_count>1 & black_count>0 & ~missing(hindex_wb_schoollev) , ||state: ||ncesid:, vce(robust)
eststo per_public2: mixed f1percent_public hindex_wb_schoollev hindex_wh_schoollev  court_order per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years per_free own_home_ipo aland10  median_hh_income_thous log_pop bach pres_dem per_pupil_expen  percent_catholic__90_10_ipo i.year if tract_count>1 & black_count>0  , ||state: ||ncesid:, vce(robust)
eststo per_public3: mixed f1studentenrolled_log hindex_wb_schoollev hindex_wh_schoollev  court_order per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years per_free   own_home_ipo aland10 median_hh_income_thous log_pop bach pres_dem per_pupil_expen  percent_catholic__90_10_ipo i.year if tract_count>1 & black_count>0  , ||state: ||ncesid:, vce(robust)


esttab per_public1 per_public2 per_public3 using "table_per_public_new.tex", label   title(Regression table\label{tab1}) replace  cells(b( star fmt(2)) se(par fmt(2) ) )   width(0.8\hsize) ///
 drop(lns1_1_1:_cons lns2_1_1:_cons lnsig_e:_cons  1995.year 1996.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year 2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009.year 2010.year) 

 
********************
* Create Table B.7 
********************

 * Test Scores
gen f1national_math=f1.national_math
gen f1national_read=f1.national_read

 eststo test1: mixed f1national_math hindex_wb_schoollev hindex_wh_schoollev court_order per_afnam_student per_hispanic_student  per_free per_IEP  own_home_ipo aland10 V33 median_hh_income_thous log_pop bach_orgreater pres_dem_vote per_pupil_exp i.year if tract_count>1 &  black_count>0  || state: ||ncesid:, vce(robust)
 eststo test2: mixed f1national_math TheileH_wb_ipo TheileH_wh_ipo court_order per_afnam_student per_hispanic_student   per_free per_IEP  own_home_ipo aland10 V33 median_hh_income_thous log_pop bach_orgreater pres_dem_vote per_pupil_exp i.year if tract_count>1 &  black_count>0  || state: ||ncesid:, vce(robust)
 eststo test3: mixed f1national_read hindex_wb_schoollev hindex_wh_schoollev court_order per_afnam_student per_hispanic_student  per_free per_IEP  own_home_ipo aland10 V33 median_hh_income_thous log_pop bach_orgreater pres_dem_vote per_pupil_exp i.year if tract_count>1 &  black_count>0  || state: ||ncesid:, vce(robust)
 eststo test4: mixed f1national_read TheileH_wb_ipo TheileH_wh_ipo court_order per_afnam_student per_hispanic_student   per_free per_IEP  own_home_ipo aland10 V33 median_hh_income_thous log_pop bach_orgreater pres_dem_vote per_pupil_exp i.year if tract_count>1 &  black_count>0  || state: ||ncesid:, vce(robust)

 
 
 coefplot (test1, rename(hindex_wb_schoollev = rob1)) (test2, rename(TheileH_wb_ipo = rob2)) (test3, rename(hindex_wb_schoollev = rob3) ) ///
           (test4, rename(TheileH_wb_ipo = rob4) )    , ///
			  grid( glcolor(white)) keep(TheileH_wb_ipo hindex_wb_schoollev) xtitle("Test Scores (Global Report Cards)") xline(0)  msymbol(D) mfcolor(white) scheme(s1mono) legend(off)  ///
			     graphregion(margin(l=60)) yscale(alt noline) title("95% CI for White-Black Segregation Coefficient ", span) ///
	coeflabels(rob1 = "1. Math; School Segregation" rob2 = "2. Math; Residential Segregation"  rob3= "3. Reading; School Segregation" ///
		  rob4 = "4. Reading; School Segregation" , wrap(35) notick labgap(-125)) 
		  graph export "graph_tests.pdf", as(pdf) replace

 
esttab test1 test2 test3 test4 using "table_test_old.tex", label   title(Regression table\label{tab1}) replace cells(b( star fmt(2)) se(par fmt(2) ) )  width(0.8\hsize) ///
 drop(lns1_1_1:_cons lns2_1_1:_cons lnsig_e:_cons  2003.year 2004.year 2005.year 2006.year 2007.year 2008.year ) 


	 